package com.centaline.androidsalesblog.adapter;

import android.content.Context;
import android.view.View;

import com.centaline.androidsalesblog.R;
import com.centaline.androidsalesblog.adapter.viewholder.ShareVH;
import com.centaline.androidsalesblog.iml.RecyclerViewItemOnClickListener;
import com.centanet.framework.base.BaseAdapter1;

/**
 * 分享
 * Created by guilin on 16/5/9.
 */
public class ShareAdapter extends BaseAdapter1<ShareVH> {

    final String[] titles;
    final int[] imgRes;
    final RecyclerViewItemOnClickListener<Integer> itemOnClickListener;

    public ShareAdapter(Context context, String[] titles, int[] imgRes,
                        RecyclerViewItemOnClickListener<Integer> itemOnClickListener) {
        super(context);
        this.titles = titles;
        this.imgRes = imgRes;
        this.itemOnClickListener = itemOnClickListener;
        if (titles.length != imgRes.length) {
            throw new IllegalArgumentException("长度不一致");
        }
    }

    @Override
    protected int inflateByLayoutId() {
        return R.layout.item_share;
    }

    @Override
    protected ShareVH viewHolder(View view) {
        return new ShareVH(view);
    }

    @Override
    public void onBindViewHolder(final ShareVH holder, int position) {
        holder.atv_title.setText(titles[position]);
        holder.img_icon.setImageResource(imgRes[position]);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemOnClickListener.onItemOnClick(holder.getAdapterPosition(), 0);
            }
        });
    }

    @Override
    public int getItemCount() {
        return titles.length;
    }
}
